﻿using System.Web;
using System.Web.Routing;

namespace Kratos.Framework.Extensions.RouteExtensions
{
    public static class RouteValueDictionaryExtensions
    {
        //request存在的key直接跳过,不存在的加进RouteValueDictionary
        public static RouteValueDictionary GetRouteValue(this HttpRequestBase request, params string[] parms)
        {
            var values = new RouteValueDictionary();
            var requestValues = request.RequestType == "GET" ? request.QueryString : request.Form;

            foreach (var key in requestValues.AllKeys)
            {
                bool skip = false;

                foreach (string parm in parms)
                {
                    if (parm == key)
                    {
                        skip = true;
                    }
                }

                if (skip) continue;

                values.Add(key, requestValues[key]);
            }

            return values;
        }
    }
}
